import { isBrowser } from './util'

export const watchSession = () => {
  if (isBrowser()) {
    const store = window.$nuxt.$store
    const user = store.getters.im_user
    // console.log(user, 'watch user', user)
    store.watch(
      (state) => state.IM.sessions,
      (val) => {
        // console.log(val, 'watch', user.id)

        localStorage.setItem('vuex-im-session-' + user.id, JSON.stringify(val))
      },
      {
        deep: true
      }
    )
  }
}
